//用户列表的小仓库 =》随机推荐的用户信息 + 心动模式(编辑距离算法推荐)用户信息列表
// 引入defineStore用于创建store
import {defineStore} from 'pinia'
import {getCurrentUserAPI} from "../../api/userApi.ts";


// 定义并暴露一个store
export const userStore = defineStore('User',{
    // 动作
    actions:{
        getUserRecommendList(){
            return this.userRecommendList;
        },
        getUserMatchList(){
            return this.userMatchList;
        },
        async getCurrentUser(){
            //只有这样才可以判断这个用currentUser是不是空的，而且必须有属性值！不能只是{} //因为刷新页面会出现currentUser会没掉(缓存没了)
            if (Object.keys(this.currentUser).length == 0){
                const res = await  getCurrentUserAPI();
                if (200 == res.code){
                    //console.log("res");
                    this.currentUser = res.data;
                }
                return this.currentUser;
            }else {
                //console.log("currentUser",this.currentUser.id)
                return this.currentUser;
            }
        },
        getOtherUserInfo(){
            return this.otherUserInfo;
        },
        setUserRecommendList(data:[]){
            this.userRecommendList = data;
        },
        setUserMatchList(data:[]){
            this.userMatchList = data;
        },
        setCurrentUser(data:any){
            this.currentUser = data;
        },
        setOtherUserInfo(data:any){
            this.otherUserInfo = data;
        }
    },
    // 状态
    state(){
        return {
            //用户的信息列表
            userRecommendList: [],
            userMatchList: [],
            currentUser:{},
            otherUserInfo:{},
        }
    },
    // 计算
    getters:{}
})
